use std::path::PathBuf;

use structopt::StructOpt;
use anyhow::Result;

use sector::SectorCommand;
use index::IndexCommand;


pub mod common;
mod sealing;
mod sector;
mod index;

#[derive(StructOpt, Debug)]
#[structopt(name = "shovel", setting = structopt::clap::AppSettings::ColoredHelp)]
pub struct Application {
    #[structopt(short, long, parse(from_os_str))]
    pub log: Option<PathBuf>,

    #[structopt(subcommand)]
    command: Option<Command>,
}

impl Application {
    pub async fn run(self) -> Result<Option<Box<dyn Output>>> {
        match self.command {
            Some(r) => r.run().await,
            None => Ok(Option::None),
        }
    }
}

#[derive(StructOpt, Debug)]
pub enum Command {
    #[structopt(name = "sector", about = "tools for sector theme")]
    Sector(SectorCommand),
    #[structopt(name = "index", about = "operate index")]
    Index(IndexCommand),
}


impl Command {
    pub async fn run(self) -> Result<Option<Box<dyn Output>>> {
        match self {
            Command::Sector(c) => c.run().await,
            Command::Index(c) => c.run().await,
        }
    }
}


pub trait Output {
    fn show(&self) -> String;
}

#[derive(StructOpt, Debug)]
pub struct SectorInput{
    #[structopt(long)]
    pub number: u64,
    #[structopt(long)]
    pub miner: u64,
}